package echat.future.cn.echat.message.adapter;

import android.support.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.message.bean.MyCallBean;
import echat.future.cn.echat.my.weight.CircleImageView;

/**
 * 我的通话
 * Created by JX on 2018/8/13.
 */

public class MyCallAdapter extends BaseQuickAdapter<MyCallBean, BaseViewHolder> {

    public MyCallAdapter(int layoutResId, @Nullable List<MyCallBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyCallBean item) {
        //头像
        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(R.mipmap.ic_launcher);
        Glide.with(mContext).load(item.getAvatar()).apply(options).into((CircleImageView)helper.getView(R.id.iv_head));
        //名字
        helper.setText(R.id.tv_name, item.getUsername());
        //日期
        helper.setText(R.id.tv_date, "消费日期："+transferLongToDate(item.getCreate_time() * 1000));
        //通话时长
        helper.setText(R.id.tv_time, "通话时长："+item.getChat_time()+"分");
        //消费
        helper.setText(R.id.tv_money, "消费支出："+item.getE_money()+"E币");
        //级别
        helper.setText(R.id.tv_jibie, "LV." + item.getLevel());
    }

    /**
     * 把long 转换成 日期 再转换成String类型
     */
    public String transferLongToDate(Long millSec) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        Date date = new Date(millSec);
        return sdf.format(date);
    }

//    public static String formatDateTime(long mss) {
//        String DateTimes = null;
//        long days = mss / ( 60 * 60 * 24);
//        long hours = (mss % ( 60 * 60 * 24)) / (60 * 60);
//        long minutes = (mss % ( 60 * 60)) /60;
//        long seconds = mss % 60;
//        if(days>0){
//            DateTimes= days + "天" + hours + "小时" + minutes + "分"
//                    + seconds + "秒";
//        }else if(hours>0){
//            DateTimes=hours + "小时" + minutes + "分"
//                    + seconds + "秒";
//        }else if(minutes>0){
//            DateTimes=minutes + "分"
//                    + seconds + "秒";
//        }else{
//            DateTimes=seconds + "秒";
//        }
//        return DateTimes;
//    }

}
